package com.caishi.lkx.order.service.impl;

import cn.hutool.core.util.StrUtil;
import com.zzw.common.Wrappers;
import com.zzw.common.entity.IBaseMapper;
import com.caishi.lkx.order.config.AssetsRouter;
import com.caishi.lkx.order.mapper.OrderDetailMapper;
import com.caishi.lkx.order.model.OrderDetailModel;
import com.caishi.lkx.order.model.OrderModel;
import com.caishi.lkx.order.service.IOrderDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author by keray
 * date:2021/7/14 5:29 下午
 */
@Service
public class OrderDetailServiceImpl implements IOrderDetailService {

    @Resource
    private OrderDetailMapper detailMapper;

    @Override
    public IBaseMapper<OrderDetailModel, Long> getMapper() {
        return detailMapper;
    }

    @Override
    public @NotNull long computePrice(@NotNull OrderModel orderModel, @NotNull OrderDetailModel detailModel) {
        if (detailModel.getEntityType() == null || StrUtil.isBlank(detailModel.getEntityId())) {
            throw new IllegalStateException("订单详情价格计算状态不合法，entityType entityId不合法");
        }
        //todo 价格计算
        return AssetsRouter.router.router(detailModel.getEntityType()).computePrice(orderModel, detailModel);
    }

    public List<OrderDetailModel> selectOrderDetails(String orderId) {
        return this.selectList(
                Wrappers.lambdaQuery(new OrderDetailModel())
                        .eq(OrderDetailModel::getOrderId, orderId)
        );
    }


}
